package com.ruoyi.activiti.domain.dto;

import java.util.Date;

import org.activiti.api.task.model.Task;
import org.activiti.engine.history.HistoricActivityInstance;
import org.activiti.engine.history.HistoricProcessInstance;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.core.domain.BaseEntity;

public class ActTaskDTO
        extends BaseEntity {

    private static final long serialVersionUID = 1L;

    private String id;

    private String name;

    private String status;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createdDate;

    public String getInstanceId() {
        return instanceId;
    }

    public void setInstanceId(String instanceId) {
        this.instanceId = instanceId;
    }

    private String instanceId;
    private String instanceName;
    private String definitionKey;
    private String businessKey;

    public String getAssignee() {
        return assignee;
    }

    public void setAssignee(String assignee) {
        this.assignee = assignee;
    }

    private String assignee;

    public String getStartUserId() {
        return startUserId;
    }

    public void setStartUserId(String startUserId) {
        this.startUserId = startUserId;
    }

    private String startUserId;

    public ActTaskDTO() {
    }

    public ActTaskDTO(Task task, HistoricProcessInstance processInstance) {
        buildDTO(task.getId(),  task.getAssignee(), task.getName(),processInstance.getEndTime() != null?"完成":"进行中", task.getCreatedDate(), processInstance);
    }

    public ActTaskDTO(org.activiti.engine.task.Task task, HistoricProcessInstance inst) {
        buildDTO(task.getId(), task.getAssignee(),  task.getName(), inst.getEndTime() != null?"完成":"进行中", task.getCreateTime(), inst);
    }

    public ActTaskDTO(HistoricActivityInstance task, HistoricProcessInstance inst) {
        buildDTO(task.getId(), task.getAssignee(), task.getActivityName(), inst.getEndTime() != null?"完成":"进行中", task.getStartTime(), inst);
    }

    private void buildDTO(String id, String assignee, String name, String status, Date createTime, HistoricProcessInstance inst) {
        this.id = id;
        this.name = name;
        this.instanceId = inst.getId();
        this.status = status;
        this.assignee = assignee;
        this.createdDate = createTime;
        this.instanceName = inst.getName();
        this.definitionKey = inst.getProcessDefinitionKey();
        this.businessKey = inst.getBusinessKey();

        this.startUserId = inst.getStartUserId();
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public Date getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(Date createdDate) {
        this.createdDate = createdDate;
    }

    public String getInstanceName() {
        return instanceName;
    }

    public void setInstanceName(String instanceName) {
        this.instanceName = instanceName;
    }

    public String getDefinitionKey() {
        return definitionKey;
    }

    public void setDefinitionKey(String definitionKey) {
        this.definitionKey = definitionKey;
    }

    public String getBusinessKey() {
        return businessKey;
    }

    public void setBusinessKey(String businessKey) {
        this.businessKey = businessKey;
    }
}
